//
//  TicketOrderStateCell.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/14.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "TicketOrderStateCell.h"
#import "OrderPayManager.h"
#import "OrderConfirmVC.h"
#import "TickectDetailVC.h"
@implementation TicketOrderStateCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.ReSchedulingBtn.layer.borderColor = kThemeColor.CGColor;
    [self.ReSchedulingBtn setTitleColor:kThemeColor forState:UIControlStateNormal];
    self.ReSchedulingBtn.layer.borderWidth = 1.0f;
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.clipsToBounds = YES;
}
- (IBAction)tapAction:(UIButton *)sender {
    
    
    if ([self getOrderStateWith:self.uploadOrderModel.orderstatus.integerValue] == SellTicket_WaitToPayment) {
        
        OrderConfirmVC * vc = [[OrderConfirmVC alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        vc.ticketOrderModel = self.uploadOrderModel;
        vc.type = 1;
        [self.superVC.navigationController pushViewController:vc animated:YES];
        
    }else if([self getOrderStateWith:self.uploadOrderModel.orderstatus.integerValue] == SellTicket_FailState || [self getOrderStateWith:self.uploadOrderModel.orderstatus.integerValue] == SellTicket_Stop){
        

        TickectDetailVC * vc = [[TickectDetailVC alloc] init];
        
        vc.hidesBottomBarWhenPushed = YES;
        vc.ticketID =  self.uploadOrderModel.unionid;
        
        [self.superVC.navigationController pushViewController:vc animated:YES];
    }
    
}


- (TicketOrderState)getOrderStateWith:(NSInteger)statue {
    
    
    switch (statue) {
        case 16:
        {
            
            return SellTicket_FailState;
        }
            break;
            
        case 0:
        case -1:
        case 2: {
            
            return SellTicket_WaitToPayment;
        }
            break;
        case 15: {
            
            return SellTicket_handling;
        }
            break;
        case 17: {
            return SellTicket_SuccessState;
        }
            break;
        case 3: {
            return SellTicket_Stop;
        }
            break;
        default:
            break;
    }
    
    return SellTicket_handling;
}

+ (CGFloat)getCellHeightWithSate:(TicketOrderState)state {
    
    CGFloat H = 45;
    CGFloat defaultH = 15;
    NSString * str = MYLocalizedString(@"TICKET_USE_TYPE_ETICKET", nil);
    if (state == SellTicket_FailState) {
        str = MYLocalizedString(@"TICKET_ERROR_INFO", nil);
    }else if(state == SellTicket_WaitToPayment){
        str = MYLocalizedString(@"TICKET_ORDER_WAITPAYMENT_DESC", nil);
    }
    H = H + [IGUtil getHeightWithText:str width:kScreenWidth - 32 lineSpacing:5 font:Font(12) defaultHeight:&defaultH];
    
    if (state == SellTicket_FailState | state == SellTicket_Stop | state == SellTicket_WaitToPayment) {
       
        H += 50;
    }
    return H;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
}

- (void)configDataWithState:(UploadTicketOrderModel *)model{
    
    self.priceLabel.text = model.realpay;
    self.uploadOrderModel = model;
    switch ([self getOrderStateWith:model.orderstatus.integerValue]) {
        case SellTicket_FailState:
        {
            self.stateExplainLabel.text = MYLocalizedString(@"TICKET_ERROR_INFO", nil);
            self.ticketStateLabel.text = MYLocalizedString(@"TICKET_ERROR_TITLE", nil);
            self.ReSchedulingBtn.hidden = NO;
            [self.ReSchedulingBtn setTitle:MYLocalizedString(@"TICKET_ORDER_RE", nil) forState:UIControlStateNormal];
        }
            break;
        case SellTicket_SuccessState:
        {
            self.ticketStateLabel.text = MYLocalizedString(@"TICKET_SUCCESS_TITLE", nil);
            self.stateExplainLabel.text = MYLocalizedString(@"TICKET_USE_TYPE_ETICKET", nil);
            //MYLocalizedString(@"TICKET_USE_TYPE_PASSPORT", nil);
            self.ReSchedulingBtn.hidden = YES;
        }
            break;
        case SellTicket_Stop:
        {
            self.stateExplainLabel.text = MYLocalizedString(@"TICKET_ORDER_OFF_DESC", nil);
            self.ticketStateLabel.text = MYLocalizedString(@"TICKET_ORDER_OFF", nil);
            self.ReSchedulingBtn.hidden = NO;
            [self.ReSchedulingBtn setTitle:MYLocalizedString(@"TICKET_ORDER_RE", nil) forState:UIControlStateNormal];
        }
            break;
        case SellTicket_handling:
        {
            self.stateExplainLabel.text = MYLocalizedString(@"TICKET_SUCCESS_TIP", nil);
            self.ticketStateLabel.text = MYLocalizedString(@"TICKET_USSUING", nil);
            self.ReSchedulingBtn.hidden = YES;
        }
            break;
        case SellTicket_WaitToPayment:
        {
            self.stateExplainLabel.text = MYLocalizedString(@"TICKET_ORDER_WAITPAYMENT_DESC", nil);
            self.ticketStateLabel.text = MYLocalizedString(@"TICKET_ORDER_WAITPAYMENT", nil);
            self.ReSchedulingBtn.hidden = NO;
            [self.ReSchedulingBtn setTitle:MYLocalizedString(@"COIN_PAY_NOW", nil) forState:UIControlStateNormal];
        }
            break;
        default:
            break;
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
